package 实验.实验二;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Car[] cars = new Car[3];
        cars[0] = new Car("Toyota", "Camry", "黑色", 100, false);
        cars[1] = new Car("Honda", "Civic", "红色", 80, false);
        cars[2] = new Car("Ford", "Focus", "银色", 90, false);
        while (true){
            System.out.println("【汽车租赁系统】");
            System.out.println("可租赁的车辆");
            for (int i = 0; i < cars.length; i++){
                if (!cars[i].isRented()){
                System.out.println(i+1+"."+cars[i].getBrand()+"  "+cars[i].getModel()+"  "+cars[i].getColor()+"  "+cars[i].getRentPrice()+"/天");
                }
            }//将遍历数组
            System.out.println("请输入你要租的车的编号（输入0退出）");
            int carIndex = scanner.nextInt();
            if (carIndex == 0){
                break;
            }//退出条件
            
            if (carIndex<1 || carIndex>cars.length){
                System.out.println("该车可以被租");
                continue;
            }
            if (cars[carIndex-1].isRented()){
                System.out.println("该车已租");
            }
            System.out.println("输入你要租的天数");
            int rentalDays = scanner.nextInt();
            if (rentalDays<=0){
                System.out.println("输入不合法");
                continue;
            }
            Rental rental = new Rental(cars[carIndex-1],rentalDays);
            double totalRent = rental.getTotalPrice();
            System.out.println(" 你 租 了 一 辆 " + cars[carIndex -1].getColor() + " " + cars[carIndex - 1].getModel() + " 共 " + rentalDays + " 天");
            System.out.println("总租金: " + totalRent+"元");
            cars[carIndex - 1].rent();
        }
    }
}
